package com.tianji.promotion.lock.strategy;

import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class LockStrategyFactory {

    private Map<LockStrategyEnum, LockStategy> map = new HashMap<>(){
        {
            put(LockStrategyEnum.FAIL_FAST, new FailFastStrategy());
            put(LockStrategyEnum.SKIP_FAST, new SkipFastStrategy());
            put(LockStrategyEnum.KEEP_TRYING, new KeepTryingStrategy());
            put(LockStrategyEnum.SKIP_AFTER_TIMEOUT, new SkipAfterTimeoutStrategy());
            put(LockStrategyEnum.FAIL_AFTER_TIMEOUT, new FailAfterTimeoutStrategy());
        }
    };

    public LockStategy getLockStrategy(LockStrategyEnum lockStrategyEnum){
        return map.get(lockStrategyEnum);
    }

}
